home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for NON-COMMERCIAL purposes and without
- * fee is hereby granted provided that this copyright notice
- * appears in all copies. Please refer to the file "LICENSE"
- * for further important copyright and licensing information.
- *
- * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
- * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
- * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
- *
- * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
- * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
- * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
- * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
- * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
- * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
- * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES"). SUN
- * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
- * HIGH RISK ACTIVITIES.
- */
-
-
- package jdbcTest.example;
-
- import java.sql.*;
- import jdbcTest.harness.*;
-
- // A test class must extend jdbcTest.harness.TestModule
- public class getString extends jdbcTest.harness.TestModule {
-
- public void run () {
-
- TestCase test;
- Connection con = null;
- java.sql.CallableStatement stmt = null;
- ResultSet rs = null;
- DatabaseMetaData meta = null;
-
- try {
-
- //Creates and executes a test case object used for
- //controlling this test case.
- test = createTestCase("Test example.getString");
- execTestCase(test);
-
- // The getUrl, getSignon, and getPassword methods provide
- // the info entered for the test run to the test.
- con = DriverManager.getConnection (getUrl(), getSignon(), getPassword());
-
- meta = con.getMetaData();
- if (!meta.supportsStoredProcedures()) {
- result("Does not support Stored Procedures");
- }
- else {
-
- stmt = con.prepareCall( "{call JDBC_GET_STRING(?)}" );
- stmt.registerOutParameter(1, java.sql.Types.CHAR);
- stmt.executeUpdate();
-
- //The test method registers the object being tested
- //and logs the method string. This is used for logging
- //what the test is attempting to do and with what
- //object.
- test(stmt, "getString()");
- String s = stmt.getString(1);
-
- //The result method logs the value of the test results.
- result(s.length());
- result(s);
-
- //If the expression is true, assert logs the fact this
- //assertion passed. If it is false, assert logs the
- //failure an aborts the test. There is a companion
- //method named verify which does the same except that
- //instead aborting it notes the failure and
- //continues. At the end a call to passed is converted
- //to a call to failed if any verify has failed.
- assert(s.equals("bc "), "The CHAR value must be 'bc '");
- // The getSupportedSQLType method returns a full type
- // description for the driver data type that
- // corresponds to SQL type. This is just data
- // retreived from DatabaseMetadata.getTypeInfo. A null
- // ref indicates there is no support for this
- // type. See SupportedSQLType.java in this directory
- // for the details.
- if (getSupportedSQLType(Types.VARCHAR) == null) {
- result("Does not support VARCHAR SQL type");
- } else {
- stmt = con.prepareCall( "{call JDBC_GET_VSTRING(?)}" );
- stmt.registerOutParameter(1, java.sql.Types.VARCHAR);
- stmt.executeUpdate();
-
- test(stmt, "getString()");
- s = stmt.getString(1);
-
- result(s.length());
- result(s);
-
- assert(s.equals("bc"), "The VARCHAR value must be 'bc'");
- }
- }
-
- //Since the test reached here it is assumed to have passed
- //unless a verify detected a failure.
- passed();
- }
- catch (Exception ex) {
-
- // The exception method handles logging all
- // exceptions. Since the test is executed in its own
- // thread it need to do its own exception handling.
- exception(ex);
- }
- finally {
- try{
- if (con != null) con.close();
- }
- catch (SQLException ex) {
- }
-
- // The stop method terminates the test's thread. This must
- // be called or the test harness will not know the test
- // has completed.
- stop();
- }
-
- }
-
- }
-